package hector.tang.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SysExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        SysException sys=null;
        if(ex instanceof SysException){
            sys=(SysException) ex;
        }else {
            sys=new SysException("系统正在维护");
        }

        ModelAndView view=new ModelAndView();
        view.addObject("error",sys.getErrorMessage());
        view.setViewName("error");

        return view;
    }
}
